package com.ty.controller;

import com.ty.common.redis.CacheUtil;
import com.ty.common.utils.GetLocationBaiduMap;
import com.ty.common.utils.SmsUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 天宇宇宇宇宇
 * @Data 2020/12/2 13:43
 */
@RestController
@Slf4j
public class HelloController {

    @Autowired
    SmsUtil smsUtil;

    /**
     * 测试redis存储
     * @return
     */
    @RequestMapping("redis")
    public String redisTest() {
        try {
            boolean b = CacheUtil.setString("123", "redis");//向redis里存字符串 key-value
            System.out.println(b);//true成功，
            System.out.println(CacheUtil.getString("123"));//从radis里取数据 key
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
        return "hello";
    }

    @RequestMapping("redis2")
    public String redisTest2() {
        CacheUtil.set("k2", "1234");
        CacheUtil.set("k3", "0987");
        CacheUtil.setString("k4", "0987");
        CacheUtil.setString("k5", "0234");
        CacheUtil.setString("k6", "acds");
        CacheUtil.set("k7", "acds");

        return "hello";
    }

    @RequestMapping("redis3")
    public String redisTest3() {

        boolean k8 = CacheUtil.setString("k8", "2345");
        System.out.println(k8);
        String k81 = CacheUtil.getString("k8");
        System.out.println(k81);

        boolean b = CacheUtil.setExp("k8", 1000);
        System.out.println(b);
        return "hello";
    }

    /**
     * 测试短信发送
     * @return
     */
    @GetMapping("smscode")
    public String smsTest(){
        smsUtil.sendSms("17760793720", SmsUtil.getFourRandom());
        return "hello";
    }

    /**
     * 测试地址逆解析
     * @return
     */
    @GetMapping("getLocationByBaiduMapTest")
    public String getLocationByBaiduMapTest(String lng, String lat) throws Exception {
        String locationByBaiduMap = GetLocationBaiduMap.getLocationByBaiduMap(lng, lat);
        log.info("解析到的地址为" + locationByBaiduMap);
        return locationByBaiduMap;
    }
}
